home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / tri14dev.lha / Triton / Developer / AmigaE / Mac2EFront / Mac2EFront.e < prev   
Text File  |  1995-08-25  |  6KB  |  182 lines

  1. /*    Mac2EFront V1.00
  2.      By Frank Verheyen, 1994
  3.      This command is meant TO be bound into your compilation-script
  4.      Parameters:
  5.         destinationfile, the file in which translated source will be dumped
  6.         sourcefile, the file with your code & macros used in it
  7.  
  8.     Inside the sourcefile, a line of the form
  9.         /* MAC2E macrofile */
  10.      (mind the uppercase OF MAC2E, so just mentioning 'mac2e' or 'Mac2E' etc.
  11.     in a comment or inside your code won't trigger this program; only total
  12.     UPPERCASE will do so.)
  13.      It announces this sourcefile should be treated with Mac2E AND the macrofile
  14.      before compilation.
  15.      Put the command inside remarks, so it won't disturb normal code.
  16.  
  17.     Note: currently only one macrofile can be treated per sourcefile,
  18.         maybe I'll change that sometimes :)
  19.  
  20. */
  21.  
  22. OPT OSVERSION=37
  23. CONST MAXPATH=500
  24.  
  25. ENUM ER_NONE,ER_BADARGS,ER_UTIL,ER_ITARG,ER_COML
  26. ENUM ER_OPENFILE,ER_READFILE,ER_FILEEMPTY,ER_NOMEM
  27. ENUM ARG_DEST,ARG_SRC,NUMARGS
  28.  
  29. MODULE 'dos/dosasl', 'dos/dos', 'utility'
  30. /*--------------------------------------------------------------------------*/
  31. RAISE ER_OPENFILE IF Open()=NIL,
  32.     ER_NOMEM IF New()=NIL
  33. /*--------------------------------------------------------------------------*/
  34. /*--------------------------------------------------------------------------*/
  35. PROC main()
  36.     DEF src,dest
  37.     DEF src1,dest1
  38.     DEF macfile=NIL
  39.  
  40.     get_arguments({src},{dest})
  41.  
  42.     dest1 := cloneString(dest)
  43.     src1 := cloneString(src)
  44.     WriteF('Invoking Mac2EFront <\s> <\s>\n',dest1,src1)
  45.     macfile := parseSource(src1)
  46.     IF macfile<>0
  47.         IF StrCmp(macfile,'')=NIL THEN invokeMac2E(src1,dest1,macfile)
  48.     ENDIF
  49. ENDPROC
  50. /*--------------------------------------------------------------------------*/
  51. PROC parseSource(src) HANDLE
  52.     DEF fh=NIL,flen=0,buf=NIL,len=0
  53.     DEF t,g,foundflag,foundpos,grabcount
  54.     DEF maccommand[MAXPATH]:STRING
  55.     DEF macfile[MAXPATH]:STRING
  56.  
  57.     WriteF('Parsing \s\n',src)
  58.     StrCopy(maccommand,'MAC2E')
  59.  
  60.     IF (fh := Open(src,OLDFILE))
  61.         flen := FileLength(src)
  62.         IF flen>0
  63.             buf := New(flen+1)       /* will be filled with 0 */
  64.             IF (Read(fh,buf,flen)<>flen)
  65.                     Raise(ER_READFILE)
  66.                ELSE
  67.                    len := StrLen(maccommand)
  68.                     FOR t := 0 TO flen-len
  69.                         IF buf[t] = maccommand[0]
  70.                             foundflag := TRUE
  71.                             FOR g := 0 TO len-1
  72.                                 IF buf[t+g] <> maccommand[g] THEN foundflag := FALSE
  73.                             ENDFOR
  74.                             IF foundflag
  75.                                   foundpos := t+len
  76.                             StrCopy(macfile,'')        -> start clean
  77.                                   grabcount := 0
  78.                                   WHILE buf[foundpos]=" " OR buf[foundpos]="\t"
  79.                                       INC foundpos
  80.                                   ENDWHILE
  81.                                   WHILE buf[foundpos+grabcount]<>" " AND buf[foundpos+grabcount]<>"*"
  82.                                        macfile[grabcount] := buf[foundpos+grabcount]
  83.                                        INC grabcount
  84.                             ENDWHILE
  85.  
  86.                             macfile[grabcount] := 0    -> add tail-zero
  87.                             IF buf THEN Dispose(buf)
  88.                             IF fh THEN Close(fh)
  89.                             WriteF('MAC2E command encountered: macrofile =\s\n',macfile)
  90.                             RETURN cloneString(macfile)
  91.                             ENDIF
  92.                            ENDIF
  93.                        ENDFOR
  94.  
  95.                     WriteF('Sourcefile doesn\at seem to be needing Macrofiles.\n')
  96.             ENDIF
  97.             IF buf THEN Dispose(buf)
  98.         ELSE
  99.              Raise(ER_FILEEMPTY)
  100.         ENDIF
  101.           Close(fh)
  102.     ENDIF
  103.  
  104.     CleanUp(0)
  105. EXCEPT
  106.     SELECT exception
  107.         CASE ER_OPENFILE
  108.             WriteF('File error: could not Open file\n')
  109.         CASE ER_READFILE
  110.             WriteF('File error: could not Read file\n')
  111.           CASE ER_FILEEMPTY
  112.               WriteF('File error: sourcefile is empty\n')
  113.     ENDSELECT
  114.      IF fh THEN Close(fh)
  115.      IF buf THEN Dispose(buf)
  116.      CleanUp(0)
  117. ENDPROC 0
  118. /*--------------------------------------------------------------------------*/
  119. PROC invokeMac2E(src,dest,macfile)
  120.     DEF con
  121.     DEF command[500]:STRING
  122.  
  123.       IF con:=Open('con:0/20/639/100/Mac2EFront V1.0',NEWFILE)
  124.           conout := con
  125.           stdout := con
  126.  
  127.         WriteF('Processing sourcefile \s\n',src)
  128.         WriteF('into destinationfile \s\n',dest)
  129.         WriteF('using macrofile \s\n\n',macfile)
  130.  
  131.           StrCopy(command,'E:bin/Mac2E ')
  132.           StrAdd(command,src)
  133.           StrAdd(command,' ')
  134.           StrAdd(command,dest)
  135.           StrAdd(command,' E:MacroFiles/')
  136.           StrAdd(command,TrimStr(macfile))
  137.  
  138.         WriteF('Executing:')
  139.         WriteF('<\s>',command)
  140.         Execute(command,0,con)
  141.  
  142.         WriteF('\nDone\n')
  143.         conout := NIL
  144.         Close(con)
  145.     ENDIF
  146. ENDPROC
  147. /*--------------------------------------------------------------------------*/
  148. PROC get_arguments(src,dest) HANDLE
  149.     DEF args[NUMARGS]:LIST,x,rdargs=NIL
  150.  
  151.     IF (utilitybase:=OpenLibrary('utility.library',37))=NIL THEN Raise(ER_UTIL)
  152.     FOR x:=0 TO NUMARGS-1 DO args[x]:=0        /* fill array with 0 */
  153.     rdargs:=ReadArgs('SRC,DEST',args,NIL)
  154.     IF rdargs=NIL THEN Raise(ER_BADARGS)
  155.  
  156.     ^src := args[ARG_SRC]
  157.     ^dest := args[ARG_DEST]
  158.  
  159.     IF utilitybase THEN CloseLibrary(utilitybase)
  160.     IF rdargs THEN FreeArgs(rdargs)
  161.  
  162. EXCEPT
  163.     SELECT exception
  164.         CASE ER_BADARGS
  165.             WriteF('Bad Arguments ...\n')
  166.         CASE ER_COML;
  167.             WriteF('No commandline specified\n')
  168.         CASE ER_UTIL;
  169.             WriteF('Couldn\at open utility.library v37\n')
  170.         CASE ERROR_BUFFER_OVERFLOW;
  171.             WriteF('Internal error\n')
  172.     ENDSELECT
  173. ENDPROC
  174. /*--------------------------------------------------------------------------*/
  175. -> cloneString(): make a new string, clone original in it, return address of clone
  176. PROC cloneString(s:PTR TO CHAR)
  177.     DEF clone
  178.     clone := String(StrLen(s))
  179.     StrCopy(clone,s,ALL)
  180. ENDPROC clone
  181. /*--------------------------------------------------------------------------*/
  182.